package com.lvcoding.miaoshademo.exception;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.lvcoding.miaoshademo.util.Res;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @description 描述
 * @date   2022-01-11 下午5:52
 * @author  wuyanshen
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Res exception(Exception ex) {
        log.error(ExceptionUtil.stacktraceToString(ex));
        if (ex.getMessage()!=null) {
            return Res.fail(ex.getMessage());
        }
        return Res.fail("系统异常，请联系管理员");
    }
}
